
<template>
<<<<<<< HEAD
  <!-- 新增窗口 -->
  <a-form
    :model="formObj"
    :label-col="{ span: 5 }"
    :wrapper-col="{ span: 14 }"
    @submit="handleSubmit"
  >
    <a-row>
      <a-col :span="8">
        <a-form-item label="货物编号:">
          <a-input v-model:value="formObj.go_id" />
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-form-item>
          <a-button type="primary" html-type="submit"> 查询 </a-button>
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-button type="primary" @click="nextOrder"> 下一单 </a-button>
      </a-col>
    </a-row>
  </a-form>
  <a-table :columns="columns" :data-source="datasource"> </a-table>
  <a-row>
    <a-col :span="4">
      <h1>总金额：</h1>
    </a-col>
    <a-col :span="8">
      <b>
        {{ totolPrice }}
      </b>
    </a-col>
  </a-row>
  <a-row>
    <a-col :span="8">
      <a-button type="primary" @click="endTotal"> 结账 </a-button>
    </a-col>
    <a-col :span="8">
      <a-button type="primary" @click="addScoreMethod"> 选择会员 </a-button>
    </a-col>
  </a-row>
=======
    <!-- 新增窗口 -->
    <a-form
        :model="formObj"
        :label-col="{ span: 5 }"
        :wrapper-col="{ span: 14 }"
        @submit="handleSubmit"
    >
        <a-row>
            <a-col :span="8">
                <a-form-item label="货物编号:">
                    <a-input v-model:value="formObj.go_id" />
                </a-form-item>
            </a-col>
            <a-col :span="8">
                <a-form-item>
                    <a-button type="primary" html-type="submit">
                        查询
                    </a-button>
                </a-form-item>
            </a-col>
            <a-col :span="8">
                <a-button type="primary" @click="nextOrder"> 下一单 </a-button>
            </a-col>
        </a-row>
    </a-form>
    <a-table :columns="columns" :data-source="datasource"> </a-table>
    <a-row>
        <a-col :span="4">
            <h1>总金额：</h1>
        </a-col>
        <a-col :span="8">
            <b>
                {{ totolPrice }}
            </b>
        </a-col>
    </a-row>
    <a-row>
        <a-col :span="8">
            <a-button type="primary" @click="endTotal"> 结账 </a-button>
        </a-col>
        <a-col :span="8">
            <a-button type="primary" @click="addScoreMethod">
                选择会员
            </a-button>
        </a-col>
    </a-row>
>>>>>>> 5f10f6198a25dcc9a1d966785717ca9d10c0d8ba
</template>
<script>
import { ref, reactive } from "vue";
import { get, put, post, tip, del } from "@/common";
export default {
<<<<<<< HEAD
  setup(props, { emit }) {
    //来进行搜索的一个对象
    const formObj = reactive({
      go_id: "",
      or_id: "",
    });
    //最后来进行结算的对象
    const endTotalPrice = reactive({
      or_sum: 0,
      or_id: "",
    });
    //最后来继续给客户加积分的对象
    const addScore = reactive({
      sum: 0,
      cl_id: "",
    });

    // const visible = ref(false);
    // const execAdd = () => {
    //   post("/stock/maintenance", addObj).then((res) => {
    //     (addObj.ca_id = ""),
    //       (addObj.st_id = ""),
    //       (addObj.ty_id = ""),
    //       (addObj.ca_name = ""),
    //       (addObj.ca_unit = ""),
    //       (addObj.ca_date = ""),
    //       (addObj.ca_price = ""),
    //       (visible.value = false);
    //     tip.success("新增成功");
    //     emit("flash");
    //   });
    // };
    //最开始获取这个or_id的函数
    const getOrid = () => {
      get("/cash/getOrId", {}).then((res) => {
        orId.value = res.data;
        formObj.or_id = res.data;
        endTotalPrice.or_id = res.data;
      });
    };
    //最开始进行调用
    getOrid();

    //进行调用结账的函数
    const endTotal = () => {
      endTotalPrice.or_sum = totolPrice;
      if (endTotalPrice.or_sum != 0 && endTotalPrice != "") {
        post("/cash/endCalc", endTotalPrice).then((res) => {
          if (res.code != 530) {
            tip.success("结账成功！");
          } else {
            tip.info("结账失败");
          }
          nextOrder();
        });
      } else {
        tip.info("数据不符合规范");
      }
    };

    //调用添加用户的积分的函数
    const addScoreMethod = () => {
      let id = prompt("请输入客户id");
      addScore.sum = totolPrice;
      addScore.cl_id = id;
      post("/cash/addScore", addScore).then((res) => {
        if (res.code != 530) {
          tip.success("更新积分成功！");
        } else {
          tip.info("更新积分失败");
        }
      });
    };

    //下一单的初始化的操作
    const nextOrder = () => {
      getOrid();
      datasource.value = [];
      totolPrice.value = 0;
    };

    //获取这个表格的数据的一个函数
    const handleSubmit = (e) => {
      post("/cash/calc", formObj).then((res) => {
        (formObj.go_id = ""), tip.success("获取成功");
        let arr = res.data;
        let all = 0;
        arr.forEach((item, index) => {
          item.key = index;
        });
        datasource.value.push(arr[0]);
        datasource.value.forEach((item, index) => {
          all = all + parseFloat(item.od_price);
        });
        totolPrice.value = all;
      });
    };
    // let datasource = [
    //     {
    //         or_id: "John Brown",
    //         od_id: 32,
    //         ca_name: "New York No. 1 Lake Park",
    //         od_price: ["nice", "developer"],
    //     },
    // ];

    //表格数据列
    const columns = [
      {
        dataIndex: "or_id", //服务端数据属性名
        title: "订单编号",
      },
      {
        dataIndex: "od_id", //服务端数据属性名
        title: "订单明细编号",
      },
      {
        dataIndex: "ca_name", //服务端数据属性名
        title: "商品名称",
      },
      {
        dataIndex: "od_price", //服务端数据属性名
        title: "单位商品价格",
      },
    ];

    let datasource = ref([]); //接收表格的数据
    let totolPrice = ref(0);
    let orId = ref("");
    return {
      formObj,
      handleSubmit,
      columns,
      datasource,
      totolPrice,
      getOrid,
      orId,
      endTotal,
      addScore,
      addScoreMethod,
      nextOrder,
      //   addObj,
      //   execAdd,
    };
  },
=======
    setup(props, { emit }) {
        //来进行搜索的一个对象
        const formObj = reactive({
            go_id: "",
            or_id: "",
        });
        //最后来进行结算的对象
        const endTotalPrice = reactive({
            or_sum: 0,
            or_id: "",
        });
        //最后来继续给客户加积分的对象
        const addScore = reactive({
            sum: 0,
            cl_id: "",
        });

        // const visible = ref(false);
        // const execAdd = () => {
        //   post("/stock/maintenance", addObj).then((res) => {
        //     (addObj.ca_id = ""),
        //       (addObj.st_id = ""),
        //       (addObj.ty_id = ""),
        //       (addObj.ca_name = ""),
        //       (addObj.ca_unit = ""),
        //       (addObj.ca_date = ""),
        //       (addObj.ca_price = ""),
        //       (visible.value = false);
        //     tip.success("新增成功");
        //     emit("flash");
        //   });
        // };
        //最开始获取这个or_id的函数
        const getOrid = () => {
            get("/cash/getOrId", {}).then((res) => {
                orId.value = res.data;
                formObj.or_id = res.data;
                endTotalPrice.or_id = res.data;
            });
        };
        //最开始进行调用
        getOrid();

        //进行调用结账的函数
        const endTotal = () => {
            endTotalPrice.or_sum = totolPrice;
            if (endTotalPrice.or_sum != 0 && endTotalPrice != "") {
                post("/cash/endCalc", endTotalPrice).then((res) => {
                    if (res.code != 530) {
                        tip.success("结账成功！");
                    } else {
                        tip.info("结账失败");
                    }
                });
            } else {
                tip.info("数据不符合规范");
            }
        };

        //调用添加用户的积分的函数
        const addScoreMethod = () => {
            let id = prompt("请输入客户id");
            addScore.sum = totolPrice;
            addScore.cl_id = id;
            post("/cash/addScore", addScore).then((res) => {
                if (res.code != 530) {
                    tip.success("更新积分成功！");
                } else {
                    tip.info("更新积分失败");
                }
            });
        };

        //下一单的初始化的操作
        const nextOrder = () => {
            getOrid();
            datasource.value = [];
            totolPrice.value = 0;
        };

        //获取这个表格的数据的一个函数
        const handleSubmit = (e) => {
            post("/cash/calc", formObj).then((res) => {
                (formObj.go_id = ""), tip.success("获取成功");
                let arr = res.data;
                let all = 0;
                arr.forEach((item, index) => {
                    item.key = index;
                });
                datasource.value.push(arr[0]);
                datasource.value.forEach((item, index) => {
                    all = all + parseFloat(item.od_price);
                });
                totolPrice.value = all;
            });
        };
        // let datasource = [
        //     {
        //         or_id: "John Brown",
        //         od_id: 32,
        //         ca_name: "New York No. 1 Lake Park",
        //         od_price: ["nice", "developer"],
        //     },
        // ];

        //表格数据列
        const columns = [
            {
                dataIndex: "or_id", //服务端数据属性名
                title: "订单编号",
            },
            {
                dataIndex: "od_id", //服务端数据属性名
                title: "订单明细编号",
            },
            {
                dataIndex: "ca_name", //服务端数据属性名
                title: "商品名称",
            },
            {
                dataIndex: "od_price", //服务端数据属性名
                title: "单位商品价格",
            },
        ];

        let datasource = ref([]); //接收表格的数据
        let totolPrice = ref(0);
        let orId = ref("");
        return {
            formObj,
            handleSubmit,
            columns,
            datasource,
            totolPrice,
            getOrid,
            orId,
            endTotal,
            addScore,
            addScoreMethod,
            nextOrder,
            //   addObj,
            //   execAdd,
        };
    },
>>>>>>> 5f10f6198a25dcc9a1d966785717ca9d10c0d8ba
};
</script>
<style scoped>
</style>